package com.cw.jeeyt.service.converter.security;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.security.SecurityUserBo;
import com.cw.jeeyt.service.bo.security.SecurityUserVo;
import com.cw.jeeyt.dao.domain.security.SecurityUserModel;
import com.cw.jeeyt.dao.model.security.SecurityUserDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 用户信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:01:34
 */
public class SecurityUserConverter {
    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SecurityUserBo do2Bo(SecurityUserDo model) {
        if (model == null) {
            return null;
        }
        SecurityUserBo bo = new SecurityUserBo();
        bo.setId(model.getId());
        bo.setUsername(model.getUsername());
        bo.setPassword(model.getPassword());
        bo.setAccount(model.getAccount());
        bo.setMobile(model.getMobile());
        bo.setTelephone(model.getTelephone());
        bo.setStatus(model.getStatus());
        bo.setComment(model.getComment());
        bo.setUserState(model.getUserState());
        bo.setSex(model.getSex());
        bo.setPosition(model.getPosition());
        bo.setEmail(model.getEmail());
        bo.setType(model.getType());
        bo.setExtend(model.getExtend());
        bo.setDefaultOrgId(model.getDefaultOrgId());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setAccountNonExpired(model.getAccountNonExpired());
        bo.setAccountNonLocked(model.getAccountNonLocked());
        bo.setCredentialsNonExpired(model.getCredentialsNonExpired());
        bo.setEnabled(model.getEnabled());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SecurityUserDo bo2Do(SecurityUserBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityUserDo model = new SecurityUserDo();
        model.setId(bo.getId());
        model.setUsername(bo.getUsername());
        model.setPassword(bo.getPassword());
        model.setAccount(bo.getAccount());
        model.setMobile(bo.getMobile());
        model.setTelephone(bo.getTelephone());
        model.setStatus(bo.getStatus());
        model.setComment(bo.getComment());
        model.setUserState(bo.getUserState());
        model.setSex(bo.getSex());
        model.setPosition(bo.getPosition());
        model.setEmail(bo.getEmail());
        model.setType(bo.getType());
        model.setExtend(bo.getExtend());
        model.setDefaultOrgId(bo.getDefaultOrgId());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setAccountNonExpired(bo.isAccountNonExpired());
        model.setAccountNonLocked(bo.isAccountNonLocked());
        model.setCredentialsNonExpired(bo.isCredentialsNonExpired());
        model.setEnabled(bo.isEnabled());
        return model;
    }

    /**
     * do转vo
     *
     * @param model
     * @return
     */
    public static SecurityUserVo do2Vo(SecurityUserDo model) {
        if (model == null) {
            return null;
        }
        SecurityUserVo vo = new SecurityUserVo();
        vo.setId(model.getId());
        vo.setUsername(model.getUsername());
        vo.setPassword(model.getPassword());
        vo.setAccount(model.getAccount());
        vo.setMobile(model.getMobile());
        vo.setTelephone(model.getTelephone());
        vo.setStatus(model.getStatus());
        vo.setComment(model.getComment());
        vo.setUserState(model.getUserState());
        vo.setSex(model.getSex());
        vo.setPosition(model.getPosition());
        vo.setEmail(model.getEmail());
        vo.setType(model.getType());
        vo.setExtend(model.getExtend());
        vo.setDefaultOrgId(model.getDefaultOrgId());
        vo.setCreateBy(model.getCreateBy());
        vo.setCreateDate(model.getCreateDate());
        vo.setUpdateBy(model.getUpdateBy());
        vo.setUpdateDate(model.getUpdateDate());
        vo.setAccountNonExpired(model.getAccountNonExpired());
        vo.setAccountNonLocked(model.getAccountNonLocked());
        vo.setCredentialsNonExpired(model.getCredentialsNonExpired());
        vo.setEnabled(model.getEnabled());
        return vo;
    }

    /**
     * vo转do
     *
     * @param vo
     * @return
     */
    public static SecurityUserDo vo2Do(SecurityUserVo vo) {
        if (vo == null) {
            return null;
        }
        SecurityUserDo model = new SecurityUserDo();
        model.setId(vo.getId());
        model.setUsername(vo.getUsername());
        model.setPassword(vo.getPassword());
        model.setAccount(vo.getAccount());
        model.setMobile(vo.getMobile());
        model.setTelephone(vo.getTelephone());
        model.setStatus(vo.getStatus());
        model.setComment(vo.getComment());
        model.setUserState(vo.isUserState());
        model.setSex(vo.getSex());
        model.setPosition(vo.getPosition());
        model.setEmail(vo.getEmail());
        model.setType(vo.getType());
        model.setExtend(vo.getExtend());
        model.setDefaultOrgId(vo.getDefaultOrgId());
        model.setCreateBy(vo.getCreateBy());
        model.setCreateDate(vo.getCreateDate());
        model.setUpdateBy(vo.getUpdateBy());
        model.setUpdateDate(vo.getUpdateDate());
        model.setAccountNonExpired(vo.isAccountNonExpired());
        model.setAccountNonLocked(vo.isAccountNonLocked());
        model.setCredentialsNonExpired(vo.isCredentialsNonExpired());
        model.setEnabled(vo.isEnabled());
        return model;
    }

    /**
     * model转bo
     *
     * @param model
     * @return
     */
    public static SecurityUserBo model2Bo(SecurityUserModel model) {
        if (model == null) {
            return null;
        }
        SecurityUserBo bo = new SecurityUserBo();
        bo.setId(model.getId());
        bo.setUsername(model.getUsername());
        bo.setPassword(model.getPassword());
        bo.setAccount(model.getAccount());
        bo.setMobile(model.getMobile());
        bo.setTelephone(model.getTelephone());
        bo.setStatus(model.getStatus());
        bo.setComment(model.getComment());
        bo.setUserState(model.getUserState());
        bo.setSex(model.getSex());
        bo.setPosition(model.getPosition());
        bo.setEmail(model.getEmail());
        bo.setType(model.getType());
        bo.setExtend(model.getExtend());
        bo.setDefaultOrgId(model.getDefaultOrgId());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setAccountNonExpired(model.getAccountNonExpired());
        bo.setAccountNonLocked(model.getAccountNonLocked());
        bo.setCredentialsNonExpired(model.getCredentialsNonExpired());
        bo.setEnabled(model.getEnabled());
        bo.setRoleIds(model.getUserRoleIds());
        bo.setRoleNames(model.getUserRoleNames());
        return bo;
    }

    /**
     * bo转model
     *
     * @param bo
     * @return
     */
    public static SecurityUserModel bo2Model(SecurityUserBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityUserModel model = new SecurityUserModel();
        model.setId(bo.getId());
        model.setUsername(bo.getUsername());
        model.setPassword(bo.getPassword());
        model.setAccount(bo.getAccount());
        model.setMobile(bo.getMobile());
        model.setTelephone(bo.getTelephone());
        model.setStatus(bo.getStatus());
        model.setComment(bo.getComment());
        model.setUserState(bo.getUserState());
        model.setSex(bo.getSex());
        model.setPosition(bo.getPosition());
        model.setEmail(bo.getEmail());
        model.setType(bo.getType());
        model.setExtend(bo.getExtend());
        model.setDefaultOrgId(bo.getDefaultOrgId());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setAccountNonExpired(bo.getAccountNonExpired());
        model.setAccountNonLocked(bo.getAccountNonLocked());
        model.setCredentialsNonExpired(bo.getCredentialsNonExpired());
        model.setEnabled(bo.getEnabled());
        model.setUserRoleIds(bo.getRoleIds());
        model.setUserRoleNames(bo.getRoleNames());
        return model;
    }

    public static SecurityUserVo model2Vo(SecurityUserModel model) {
        if (model == null) {
            return null;
        }
        SecurityUserVo vo = new SecurityUserVo();
        vo.setId(model.getId());
        vo.setUsername(model.getUsername());
        vo.setPassword(model.getPassword());
        vo.setAccount(model.getAccount());
        vo.setMobile(model.getMobile());
        vo.setTelephone(model.getTelephone());
        vo.setStatus(model.getStatus());
        vo.setComment(model.getComment());
        vo.setUserState(model.getUserState());
        vo.setSex(model.getSex());
        vo.setPosition(model.getPosition());
        vo.setEmail(model.getEmail());
        vo.setType(model.getType());
        vo.setExtend(model.getExtend());
        vo.setDefaultOrgId(model.getDefaultOrgId());
        vo.setCreateBy(model.getCreateBy());
        vo.setCreateDate(model.getCreateDate());
        vo.setUpdateBy(model.getUpdateBy());
        vo.setUpdateDate(model.getUpdateDate());
        vo.setAccountNonExpired(model.getAccountNonExpired());
        vo.setAccountNonLocked(model.getAccountNonLocked());
        vo.setCredentialsNonExpired(model.getCredentialsNonExpired());
        vo.setEnabled(model.getEnabled());
        vo.setUserRoleIds(model.getUserRoleIds());
        vo.setUserRoleNames(model.getUserRoleNames());
        return vo;
    }

    public static SecurityUserModel vo2Model(SecurityUserVo vo) {
        if (vo == null) {
            return null;
        }
        SecurityUserModel model = new SecurityUserModel();
        model.setId(vo.getId());
        model.setUsername(vo.getUsername());
        model.setPassword(vo.getPassword());
        model.setAccount(vo.getAccount());
        model.setMobile(vo.getMobile());
        model.setTelephone(vo.getTelephone());
        model.setStatus(vo.getStatus());
        model.setComment(vo.getComment());
        model.setUserState(vo.isUserState());
        model.setSex(vo.getSex());
        model.setPosition(vo.getPosition());
        model.setEmail(vo.getEmail());
        model.setType(vo.getType());
        model.setExtend(vo.getExtend());
        model.setDefaultOrgId(vo.getDefaultOrgId());
        model.setCreateBy(vo.getCreateBy());
        model.setCreateDate(vo.getCreateDate());
        model.setUpdateBy(vo.getUpdateBy());
        model.setUpdateDate(vo.getUpdateDate());
        model.setAccountNonExpired(vo.isAccountNonExpired());
        model.setAccountNonLocked(vo.isAccountNonLocked());
        model.setCredentialsNonExpired(vo.isCredentialsNonExpired());
        model.setEnabled(vo.isEnabled());
        model.setUserRoleIds(vo.getUserRoleIds());
        model.setUserRoleNames(vo.getUserRoleNames());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SecurityUserBo> doList2BoList(List<SecurityUserDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityUserConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SecurityUserDo> boList2DoList(List<SecurityUserBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityUserConverter::bo2Do));
    }

    /**
     * doList转voList
     *
     * @param doList
     * @return
     */
    public static List<SecurityUserVo> doList2VoList(List<SecurityUserDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityUserConverter::do2Vo));
    }

    /**
     * voList转doList
     *
     * @param voList
     * @return
     */
    public static List<SecurityUserDo> voList2DoList(List<SecurityUserVo> voList) {
        if (CollectionUtil.isEmpty(voList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(voList.iterator(), SecurityUserConverter::vo2Do));
    }

    /**
     * modelList转boList
     *
     * @param modelList
     * @return
     */
    public static List<SecurityUserBo> modelList2BoList(List<SecurityUserModel> modelList) {
        if (CollectionUtil.isEmpty(modelList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(modelList.iterator(), SecurityUserConverter::model2Bo));
    }

    /**
     * boList转modelList
     *
     * @param boList
     * @return
     */
    public static List<SecurityUserModel> boList2ModelList(List<SecurityUserBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityUserConverter::bo2Model));
    }

    /**
     * modelList转voList
     *
     * @param modelList
     * @return
     */
    public static List<SecurityUserVo> modelList2VoList(List<SecurityUserModel> modelList) {
        if (CollectionUtil.isEmpty(modelList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(modelList.iterator(), SecurityUserConverter::model2Vo));
    }

    /**
     * voList转modelList
     *
     * @param voList
     * @return
     */
    public static List<SecurityUserModel> voList2ModelList(List<SecurityUserVo> voList) {
        if (CollectionUtil.isEmpty(voList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(voList.iterator(), SecurityUserConverter::vo2Model));
    }

}
